<?php 
	require_once("libs/includes.php");
	global $connection;
	$connection = set_connection();
	
	$languages = get_languages();
	$categories = get_category_hierarchy($_SESSION["language"]["id"]);
	
	$page = get_page();
	
	$site_pages = get_site_pages();
	
	$settings = get_settings();
	
	$translations = get_translations();
	
	if($_SESSION["language"]["locale"] != "")
	{
		$locale = setlocale(LC_TIME, $_SESSION["language"]["locale"]);
	}
	$client = getLoginData();
	
	if($client)
	{
		if(isset($page["page_slug"]) && $page["page_slug"] == "login")
		{
			header("Location:".$site_pages["profile"]["url"]);
		}
	}
	elseif(@$page["page_slug"] == "profile")
	{
		header("Location:".$site_pages["login"]["url"]);
	}
	
?>
<!DOCTYPE html>
	<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
	<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
	<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
	<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

	<?php include("head.php"); ?>
	<body>
		<input type="hidden" id="base_url" value="<?php echo scripts_url(); ?>" />
	<!--[if lt IE 7]>
	    <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
	<![endif]-->
	
	<div id="fb-root">&nbsp;</div>
		<header>
			<div class="container">
			            <div class="col-md-5" id="logoHolder">
		                	<a id="logo" href="<?php echo site_url(); ?>"><img src="<?php echo scripts_url(); ?>img/logo.png" alt=""></a>
		                 	<button type="button" class="navbar-toggle navbar-left" data-toggle="collapse" data-target=".navbar-collapse">
		                    	<span class="icon-bar"></span>
			                    <span class="icon-bar"></span>
			                    <span class="icon-bar"></span>
		                  	</button>
	
		                  	<button type="button" class="sidebar-collapse btn btn-default btn-md visible-xs" data-toggle="collapse" data-target="#sidebar">
	                			<span class="glyphicon glyphicon-filter"></span>
		                  	</button>
		                  	<div class="clearfix"></div> 
		                  	<div class="languages">
	                  			<span><?php echo translate("change_language"); ?>:</span>
	                  			
	                  			<?php foreach($languages as $lang):?>
			                		<a class="lang_<?php echo strtolower($lang["abv"]);?>" 
			                				href="<?php echo scripts_url(); echo ($lang["is_default"] == 0) ? strtolower($lang["abv"]).'/' : ''; ?>" 
			                				title="<?php echo $lang["name"];?>">
			                			<span><?php echo $lang["abv"]; ?><span>
			                		</a>
			                	<?php endforeach;?>
		                  	</div>
			            </div>
			            <div class="col-md-7 " id="headerLinks">
			            	
			            	<div id="cartContainer" class="visible-lg visible-md navbar-right">
								<?php getHeaderCart(); ?>
		                	</div>
		                	<?php if(isset($client["id"])):?>
		            			<div class="row">
			            			<a href="<?php echo site_url();?>logout.html" id="logout" class="navbar-btn navbar-right loginName" title="<?php echo translate("logout"); ?>"><?php echo strtolower(translate("logout")); ?></a>
			            			<a class="navbar-btn navbar-right loginName" href="<?php echo $site_pages["account"]["url"];?>"><?php echo $client["name"]; ?></a>
			            			<span class="navbar-btn navbar-right green"><?php echo translate("logged_in_as"); ?>: </span>
			            			<a class='navbar-btn navbar-right' href='<?php echo $site_pages["wishlist"]["url"];?>'><?php echo $site_pages["wishlist"]["name"]; ?></a>
		            			</div>
			                <?php else: ?>
			                	<a class='navbar-btn navbar-right profile' href='<?php echo $site_pages["login"]["url"];?>'><?php echo translate("login"); ?></a>
		                		<a class='navbar-btn navbar-right register' href='<?php echo $site_pages["account"]["url"];?>'><?php echo translate("register"); ?></a>
			                <?php endif; ?>
		                	
		                	
		                </div>
	  			<div class="clearfix"></div>
	  		</div>
	  		<div class="clearfix"></div>
			<div class="container menuHolder">
		      			<div class="col-md-12">
		      				<div class="row" id="topMenu">
		      					<?php
		      						$selectedCategory = false;
		      						if(!isset($_GET["super_category"]))
									{
										$categories[0]["selected"] = true;
									}
		      					?>
		      					<?php foreach($categories as $category):?>
		          					<a title="<?php echo $category["name"]?>" href="<?php echo site_url().$category["url"]; ?>" class="<?php echo ((isset($category["selected"]) && $category["selected"]) ? "selected" : "");?>"><?php echo $category["name"]; ?></a>
		          					
		          					<?php 
		          						if(isset($category["selected"]) && $category["selected"])
										{
											$selectedCategory = $superCategory = $category;
										}
										elseif(isset($_GET["super_category"]) && $category["slug"] == $_GET["super_category"])
										{
											$selectedCategory = $superCategory = $category;
										}
		          					?>
		          					
		          				<?php endforeach; ?>
							</div>
							<div class="row pull-up" id="menu">
								<div class="col-md-5">
									<ul>
										<li class="selected">
											<a href="#" title="">
												<?php echo $superCategory["alt_title"]; ?>
												<span class="glyphicon glyphicon-chevron-down" style=""></span>
											</a>
											<ul class="">
												<?php foreach($superCategory["children"] as $category):?>
													<?php
													 	if(isset($_GET["category"]) && $category["slug"] == $_GET["category"])
														{
															$parentCategory = $selectedCategory = $category;
														}
													?>
													<li class="<?php echo ((isset($category["selected"]) && $category["selected"]) ? "selected" : "" );?>">
														<a title="<?php echo $category["name"]?>" href="<?php echo site_url().$category["url"]; ?>">
															<span class="glyphicon glyphicon-play"></span>
															<?php echo $category["name"]; ?>
															
															<?php if(isset($category["children"]) && count($category["children"]) > 0):?>
																<span class="arrow"></span>
															<?php endif;?>
														</a>
														<?php if(isset($category["children"]) && count($category["children"]) > 0):?>
															<ul class="">
																<?php foreach($category["children"] as $subcategory):?>
																	<?php
																		if(isset($_GET["sub_category"]) && $subcategory["slug"] == $_GET["sub_category"])
																		{
																			$subCategory = $selectedCategory = $subcategory;
																		}
																	?>
																		<li><a title="<?php echo $subcategory["name"]?>" href="<?php echo site_url().$subcategory["url"];?>">
																			<span class="glyphicon glyphicon-play"></span>
																			<?php echo $subcategory["name"]; ?>
																		</a></li>
																<?php endforeach; ?>
															</ul>
														<?php endif; ?>
													</li>
												<?php endforeach; ?>
											</ul>
										</li>
									</ul>
								</div>
								<div class="col-md-7 searchHolder">
									<form class="form-inline" method="post" action="#">
										 <div class="form-group searchInput">
										    <input style="width:235px;" type="text" class="form-control" placeholder="cauta nume produs cod produs" />
										    <div class="magnifier"></div>
										  </div>
										  <div class="form-group">
										  	<select style="width:200px;" class="form-control" name="category_id" id="categorySelect">
										  		<?php foreach($categories as $supercat): ?>
											  		<option value="<?php echo $supercat["id"]?>"><?php echo $supercat["name"]?></option>
											  		<?php if(isset($supercat["children"])):?>
											  			<?php foreach($supercat["children"] as $parentCat): ?>
											  				<option value="<?php echo $parentCat["id"]?>">&nbsp;&nbsp; <?php echo $parentCat["name"]?></option>
											  			<?php endforeach; ?>
											  		<?php endif;?>
											  	<?php endforeach;?>
											</select>
										  </div>
										  <button class="btn btn-success" type="button">gaseste</button>
										  <div class="clearfix"></div>
									</form>
									<div class="col-md-11 col-md-offset-1 keywords">cautari frecvente: <a href="#" title="">scaun pliabil</a>, <a href="#" title="">canapea extensibila</a>, <a href="#" title="">scaun pliabil</a>, <a href="#" title="">canapea extensibila</a></div>
									<div class="clearfix"></div>
								</div>
		      				</div>
		      			</div>
			</div>
		</header>